#include "joinmeet.hpp"
#include "db/sqlite_conn.hpp"



#include <math.h>

namespace bz
{

	REFLECTION(joinmeet, id, objectid, name, rxaudiomute, qualitymain,
		qualitypresentation, participantlabels, presentationcontributionallowed)

	joinmeet::joinmeet()
	{
		
	}

	joinmeet::~joinmeet()
	{
	}

	void joinmeet::init()
	{
		ormpp_auto_key auto_key{
		"id"
		};
		auto db = sqlite_conn::get_conn();
		sqlite_guard guard(db);
		db->set_auto_key<joinmeet>(auto_key);
	}

	bool joinmeet::get()
	{
		auto db = sqlite_conn::get_conn();
		sqlite_guard guard(db);
		auto res = db->query(FID(joinmeet::id), "=", id);
		if (res.size() > 0) {
			*this = res[0];
			return true;
		}
		return false;
	}

	std::string joinmeet::index()
	{
		auto db = sqlite_conn::get_conn();
		sqlite_guard guard(db);
		auto rows = db->query<joinmeet>();
		json lists = json::array();
		for (auto it : rows)
		{
			json row;
			to_json(row, it);
			lists.push_back(row);
		}
		return lists.dump();
	}

	int joinmeet::add()
	{
		auto db = sqlite_conn::get_conn();
		sqlite_guard guard(db);
		return db->insert(*this);
	}

	bool joinmeet::remove()
	{
		auto db = sqlite_conn::get_conn();
		sqlite_guard guard(db);
		return db->delete_records(FID(joinmeet::id), "=", id);
	}

	int joinmeet::update()
	{
		auto db = sqlite_conn::get_conn();
		sqlite_guard guard(db);
		return db->update(*this);
	}

	
}